package yz;

/**
 * [面试题 03.01. 三合一](https://leetcode-cn.com/problems/three-in-one-lcci/)
 *
 * @Author yangz
 * @Date 2022/11/18 20:33
 */
public class LeetCode0301_ThreeInOneLcci {
    //栈大小
    private final int STACK_SIZE;
    //当前栈的栈顶指针
    private int[] index;
    //栈
    private int[][] stack;

    public LeetCode0301_ThreeInOneLcci(int stackSize) {
        this.STACK_SIZE = stackSize;
        this.index = new int[]{-1, -1, -1};
        this.stack = new int[3][STACK_SIZE];
    }

    public void push(int stackNum, int value) {
        //判断当前栈是否已满
        if (index[stackNum] + 1 < STACK_SIZE) {
            //向栈内添加元素
            stack[stackNum][++index[stackNum]] = value;
            //栈顶指针上移一位
            //index[stackNum]++;
        }
    }

    public int pop(int stackNum) {
        //判断当前栈是否已空
        if (isEmpty(stackNum)) {
            return -1;
        }
        //将栈顶指针向下移一位
        //index[stackNum]--;
        //返回抛出的元素
        return stack[stackNum][index[stackNum]--];
    }

    public int peek(int stackNum) {
        //判断当前栈是否已空
        if (isEmpty(stackNum)) {
            return -1;
        }
        //返回栈顶元素
        return stack[stackNum][index[stackNum]];
    }

    public boolean isEmpty(int stackNum) {
        //判断当前栈是否已空
        return index[stackNum] == -1;
    }
}
